package org.noip2.noskamaru.katsys;

import java.net.UnknownHostException;
import java.util.ArrayList;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;
 
public class Usernametest {
	public static MongoClient mongoClient;
	public static DB db;
	public static DBCollection coll;
	public Usernametest() throws UnknownHostException {
		String url = "lynx:10001,lynx:10002,lynx:10003";
		ArrayList<ServerAddress> addr = new ArrayList<ServerAddress>();
		for (String s: url.split(",")) {
		    addr.add(new ServerAddress(s));
		}
		Mongo mongo = new Mongo(addr);
		db = mongo.getDB( "katsys" );
		coll = db.getCollection("users");
		
	}
	
	public static boolean loginClient(String cname,String cpass)	{
		BasicDBObject query = new BasicDBObject();
		query.put("name", cname);
		query.put("password", cpass);
		DBCursor cursor= coll.find(query);
				if(cursor.hasNext())	{
					return true;
				}
				else	{
					return false;
				}
				

	}

}
